/*
 * Copyright 2022-2023 Bytedance Ltd. and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package com.bytedance.bitsail.flink.core.transform.builder;

import com.bytedance.bitsail.base.connector.transform.v1.Transformer;
import com.bytedance.bitsail.base.execution.ExecutionEnviron;
import com.bytedance.bitsail.common.configuration.BitSailConfiguration;
import com.bytedance.bitsail.common.option.TransformOptions;
import com.bytedance.bitsail.flink.core.transform.FlinkDataTransformDAGBuilder;

public abstract class FlinkBaseTransformerBuilder<T> extends FlinkDataTransformDAGBuilder<T> {

  protected final Transformer transformer;

  protected BitSailConfiguration commonConfiguration;
  protected BitSailConfiguration transformerConfiguration;

  public FlinkBaseTransformerBuilder(Transformer transformer) {
    this.transformer = transformer;
  }

  @Override
  public void configure(ExecutionEnviron execution, BitSailConfiguration transformConfiguration) throws Exception {
    this.commonConfiguration = execution.getCommonConfiguration();
    this.transformerConfiguration = transformConfiguration;
    this.transformer.configure(commonConfiguration, transformConfiguration.getSubConfiguration(TransformOptions.JOB_TRANSFORM));
  }

  @Override
  public String getTransformName() {
    return transformer.getComponentName();
  }
}
